home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byte0787.arc / NEWGEN.ARC / FIB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-27  |  640 b   |  30 lines

  1. #include <stdio.h>
  2.  
  3. #define NTIMES 10 /* number of times to compute Fibonacci value */
  4. #define NUMBER 24 /* biggest one we can compute with 16 bits */
  5.  
  6.  
  7. main()            /* compute Fibonacci value */
  8.      {
  9.      int i;
  10.      unsigned value, fib();
  11.  
  12.      printf("%d iterations:  ", NTIMES);
  13.     
  14.      for (i = 1; i <= NTIMES; i++)
  15.           value = fib(NUMBER);
  16.  
  17.      printf("Fibonacci(%d) = %u.\n", NUMBER, value);
  18.      exit(0);
  19.      }
  20.  
  21.  
  22. unsigned fib(x)        /* compute Fibonacci number recursively */
  23. int x;
  24.      {
  25.      if (x > 2)
  26.           return (fib(x - 1) + fib(x - 2));
  27.      else
  28.           return (1);
  29.      }